﻿#建议保存编码为：bom头 + utf8
# 启用winrm，安装插件。非必要安装ps6，或ps7。
#Requires -RunAsAdministrator

if ($env:LANG -eq 'zh_CN.UTF-8')
{
	Write-Error '信息：此脚本只能在被控机上运行。'
}
else
{
	Write-Error 'note：Information: This script can only be run on NODE'
}

if (($PSVersionTable.PSVersion.Major -lt 5) -and ($PSVersionTable.PSVersion.Minor -lt 1))
{
	Write-Error '错误：powershell版本太低。必须是powershell5.1'
	Exit 11
}

if ( ($IsWindows -eq $True) -or ($PSVersionTable.psversion.major -lt 6) ) #win
{
	$win7 = powershell.exe -command { (Get-WmiObject -Class Win32_OperatingSystem).Caption -like "*7*" }
	$win2008 = powershell.exe -command { (Get-WmiObject -Class Win32_OperatingSystem).Caption -like "*2008*" }
	if ( $win7 -or $win2008 )
	{
		Write-Warning '卡死你3000被控机，支持win7，支持win2008。'
	}

	#设定winrm
	Enable-PSRemoting -SkipNetworkProfileCheck -Force
	Set-NetFirewallRule -Name "WINRM-HTTP-In-TCP-NoScope" -RemoteAddress Any
	Set-NetFirewallRule -Name "WINRM-HTTP-In-TCP" -RemoteAddress Any
	Restart-Service WinRM   #并重启服务
}
exit 0
